package edu.sysu.cshare.util.gui;

import javax.swing.ImageIcon;
import javax.swing.table.AbstractTableModel;

import edu.sysu.cshare.control.HomeworkManager;
import edu.sysu.cshare.gui.Pnl_Homework;
import edu.sysu.cshare.model.Homework;
import edu.sysu.cshare.util.Mis;

public class TableModel_Homework_Un extends AbstractTableModel {
	@Override
	public Class<?> getColumnClass(int columnIndex) {
		return getValueAt(0, columnIndex).getClass();
	}

	HomeworkManager hm;
	final String[] columnNames = { "id", Pnl_Homework.Naming.getCourseName(),
			Pnl_Homework.Naming.getHomeworkDescrp(),
			Pnl_Homework.Naming.getDueDate(),
			Pnl_Homework.Naming.getViewDetail(),
			Pnl_Homework.Naming.getClickSubmit() };

	public TableModel_Homework_Un(HomeworkManager hm) {
		this.hm = hm;
	}

	/**
	 * courseName,HomeworkDesp,DueDate,ViewDetail,DoSubmit
	 */
	@Override
	public int getColumnCount() {

		return columnNames.length;
	}

	@Override
	public String getColumnName(int column) {

		return columnNames[column];
	}

	@Override
	public int getRowCount() {
		int count = 0;
		try {
			count = hm.getUnsubmit().size();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return count;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Object value = null;

		try {
			Homework homework = hm.getUnsubmit().get(rowIndex).getHomework();
			switch (columnIndex) {
			case 0:
				value = homework.getId();
				break;
			case 1:
				value = homework.getCourse().getName();

				break;
			case 2:
				value = homework.getDescrip();
				break;
			case 3:
				value = Mis.formatCalendar(homework.getDueDate());
				break;
			case 4:
				value = Pnl_Homework.Image.getViewDetail();
				break;
			case 5:
				if(!homework.shouldUpload()){
					value = Pnl_Homework.Image.getCheckDone();
				}else{
					value =Pnl_Homework.Image.getSubmit();
				}
				break;
			default:
				break;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return value;
	}

}
